#coding:utf-8
'''
Created on 2015��8��25��

@author: guowu
'''

def getxstr(currentindex):
    import Image 
    import sys 
    imgfile = "badapple/badapple " + "%05d"%currentindex + ".jpg"
    
    im = Image.open(imgfile) 
    im = im.resize((300,250),Image.ANTIALIAS)#消除锯齿
    #im.show()
    width = im.size[0] 
    height = im.size[1] 
    
    xstr = ""
    for h in range(0, height): 
        xcount = 0 
        ncount = 0
        for w in range(0, width): 
            pixel = im.getpixel((w, h)) 
            #img.putpixel((4,4),(255,0,0))#对像素点进行修改
            if pixel[0] == 0:
                if ncount != 0:
                    addstr = "%d"%ncount + "#"
                    xstr += addstr
                ncount = 0
                xcount += 1
                #xstr = xstr + 
            else:
                if xcount != 0:
                    addstr = "%d"%xcount + "&"
                    xstr += addstr
                xcount = 0
                ncount += 1
                #xstr = xstr + "&"
        if xcount != 0:
            addstr = "%d"%xcount + "&"
            xstr += addstr
        if ncount != 0:
            addstr = "%d"%ncount + "#"
            xstr += addstr
        
        xstr = xstr + "\n"
        
        
    return xstr

#print getxstr()
